import {createApp, h, nextTick} from 'vue';
import vant from 'vant';
import 'vant/lib/index.css';
import '@vant/touch-emulator';
import '@/components/icon/iconfont.css';
import '@/components/icon/iconfont';
import HPopup from '@comp/HPopup/HPopup.vue';

function createAppForModal(vnode, {style, props}) {
  let app = createApp({
    data() {
      return {
        show: false,
      }
    },
    mounted() {
      this.show = false
      nextTick(() => {
        this.show = true
      })
    },
    render() {
      return h(HPopup, {
        show: this.show,
        style,
        ...props,
        'onUpdate:show': show => this.show = show,
      }, vnode);
    },
    methods: {
      close() {
        this.show = false
      },
    }
  });
  app.use(vant);
  let div = document.createElement('div');
  document.body.appendChild(div);
  app.mount(div);
  return app
}

export default createAppForModal